package Code;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class DisplayPanel extends JPanel {

	private static final long serialVersionUID = 1L;

	private Grid grid;
	private int occWidth;
	private Tank tank;
	private Point goal;
	
	public DisplayPanel(final Grid grid) {
		this.grid = grid;
		this.grid.setView(this);
	}
	
	public void paint(Graphics g) {
		super.paint(g);
		
		for(int x = 0; x < grid.getWorldX(); x+=10) {
			for(int y = 10; y < grid.getWorldY(); y+=10) {
				int size = (int) (25*grid.getValue(x, y))/2;
				if(grid.getValue(x, y) > .9) {
					g.setColor(Color.BLACK);
				} else if (grid.getValue(x, y) <= .2){
					g.setColor(Color.WHITE);
				}
				else {
					g.setColor(Color.GRAY);
				}
				g.fillRect(x, y, size, size);
				//g.fillOval(x, y, size, size);
			}
		}
		g.setColor(Color.RED);
		if (tank != null)
		{
			int tankX = (int)(tank.getX() + grid.getWorldX()/2);
			int tankY = (int)(-1*tank.getY() + grid.getWorldY()/2);
			g.drawRect(tankX-10, tankY-10, 20, 20);
		
			int x1 = (int) (tankX - occWidth/2);
			int y1 = (int) (tankY - occWidth/2);
				
			int x2 = occWidth;
			int y2 = occWidth;
			g.drawRect(x1, y1, x2, y2);
			
			int goalX = (int)(goal.getX() + grid.getWorldX()/2);
			int goalY = (int)(-1*goal.getY() + grid.getWorldY()/2);
			g.fillRect(goalX-10, goalY-10, 20, 20);
		}
	}
	
	public void redraw(final Tank tank, final int occWidth, Point goal) {
		this.tank = tank;
		this.occWidth = occWidth;
		this.goal = goal;
		this.repaint();
	}
	
	
	
}
